package com.woniuxy.oldmanapi.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.oldmanapi.entity.Bedlog;
import com.woniuxy.oldmanapi.entity.Older;
import com.woniuxy.oldmanapi.service.BedLogService;
import com.woniuxy.oldmanapi.vo.ResponseResult;
import com.woniuxy.oldmanapi.xvo.BedLogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class BedLogController {
    @Autowired
    BedLogService bedLogService;
    @GetMapping("/bedLog/selectBedLogByname")
    public ResponseResult<PageInfo<BedLogVo>> selectBedLogByname(@RequestParam(defaultValue = "1") int now, @RequestParam(defaultValue = "3")int size, String name){
        ResponseResult<PageInfo<BedLogVo>> result = new ResponseResult<>();
        try {
            PageInfo<BedLogVo> pageInfo = bedLogService.selectBedLogByname(now,size,name);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
    @PostMapping("/bedLog/changeBed")
    public ResponseResult<Void> changeBed(@RequestBody Bedlog bedlog){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            bedLogService.changeBed(bedlog);
            result.setCode(200);
            result.setMsg("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
    @GetMapping("/bedLog/deleteBedLog")
    public ResponseResult<Void> deleteBedLog(int id){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            bedLogService.deleteBedLog(id);
            result.setCode(200);
            result.setMsg("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
}
